<?php
	require_once dirname(__FILE__) . "/../../includes/config.php";
	require_once PHP_ROOTPATH.'/classes/database.php';
	
	//récupération du contenu à mettre dans les onglets
	header("Content-Type: text/xml; charset=utf-8");
	echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
	echo "<list>";
	
	$desc = (isset($_POST["description"])) ? html_entity_decode($_POST["description"]) : NULL;
	$id = (isset($_POST["id_anim"])) ? html_entity_decode($_POST["id_anim"]) : NULL;
	echo $desc,$id;
	if($desc && $id){
		$id_connect=Database::getInstance();
		$query_temp1= "SELECT distinct date_test,experimentateur,mesure,resultat_test_simple.description, unite
		FROM resultat_test,test,Type_test, resultat_test_simple
		WHERE label LIKE '%".$desc."%'
		AND id_animal=".$id."
		AND resultat_test.id_test=test.id_test
		AND test.id_type_test=type_test.id_type_test
		AND resultat_test_simple.id_res=resultat_test.id_res
		ORDER BY date_test";
		
		$res_query1 = pg_query($id_connect , $query_temp1) or die(pg_last_error());
		
		while ($back1 = pg_fetch_assoc($res_query1)) {
			if($back1["date_test"]){
				echo "<item id=\"" . $desc.$back1["date_test"] . "_date\" name=\"" . date("d/m/Y", strtotime($back1["date_test"])) . "\" />";
				if($back1["experimentateur"]){
					echo "<item id=\"" . $desc.$back1["date_test"] . "_exp\" name=\"" . $back1["experimentateur"] . "\" />";
				}
				if($back1["mesure"]){
					echo "<item id=\"" . $desc.$back1["date_test"] . "_mes\" name=\"" . $back1["mesure"];
					if ($back1["unite"]) {
						echo " ".$back1["unite"];
					}		 
					echo "\" />";
				}
				if($back1["description"]){
					echo "<item id=\"" . $desc.$back1["date_test"] . "_desc\" name=\"" . $back1["description"] . "\" />";
				}
			}
		}
	}
	echo "</list>";
?>
